package com.example.function_interface.predicate;

import com.example.function_interface.User;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.DoublePredicate;

/**
 * 代表了一个两个参数的boolean值方法
 */
public class BiPredicateTest {

    @Test
    public void myTest() throws Exception{
        List<User> userList = new ArrayList<>();
        User user1 = new User(1, "张三", 12, false, 23.3);
        User user2 = new User(2, "李四", 22, false, 200);
        User user3 = new User(3, "王五", 32, true, 123.2);
        User user4 = new User(4, "郑静", 2, true, 0);
        userList.add(user1);
        userList.add(user2);
        userList.add(user3);
        userList.add(user4);

        BiPredicate<User, Integer> biPredicate = new BiPredicate() {
            @Override
            public boolean test(Object o, Object o2) {
                User user = (User) o;
                Integer age = (Integer) o2;
                return user.getAge() > age;
            }
        };


        BiPredicate biPredicate1 = biPredicate.and((user, age) -> user.getAge() < age*2);
        BiPredicate biPredicate2 = biPredicate.or((user, age) -> user.getAge() < age/2);

        System.out.println("大于age并且小于age*2："+biPredicate1.test(user2, 18));
        System.out.println("大于age或者小于age/2："+biPredicate2.test(user2, 18));

        System.out.println("小于age或者大于age*2："+biPredicate1.negate().test(user2, 18));
        System.out.println("小于age并且大于age/2："+biPredicate2.negate().test(user2, 18));

    }
}
